<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="产品id" prop="goodsId">
                <el-input v-model="queryParams.goodsId" placeholder="请输入产品id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="总价" prop="goodsTotalPrice">
                <el-input v-model="queryParams.goodsTotalPrice" placeholder="请输入总价"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="成本单价" prop="goodsBuyPrice">
                <el-input v-model="queryParams.goodsBuyPrice" placeholder="请输入成本单价"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="成本总金额" prop="goodsBuyTotal">
                <el-input v-model="queryParams.goodsBuyTotal" placeholder="请输入成本总金额"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="销售利润" prop="goodsProfit">
                <el-input v-model="queryParams.goodsProfit" placeholder="请输入销售利润"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="销售日期" prop="saleDate">
                            <el-date-picker clearable v-model="queryParams.saleDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择销售日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="供应商" prop="supplierId">
                <el-input v-model="queryParams.supplierId" placeholder="请输入供应商"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="供应商名称" prop="supplierName">
                <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="客户" prop="customerId">
                <el-input v-model="queryParams.customerId" placeholder="请输入客户"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="queryParams.customerName" placeholder="请输入客户名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="销售人" prop="saleId">
                <el-input v-model="queryParams.saleId" placeholder="请输入销售人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="销售人姓名" prop="saleName">
                <el-input v-model="queryParams.saleName" placeholder="请输入销售人姓名"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单编号" prop="projectId">
                <el-input v-model="queryParams.projectId" placeholder="请输入订单编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="是否发货" prop="isfahuo">
                <el-input v-model="queryParams.isfahuo" placeholder="请输入是否发货"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="发货时间" prop="fahuoDate">
                            <el-date-picker clearable v-model="queryParams.fahuoDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择发货时间">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="产品编码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入产品编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="吨位" prop="dun">
                <el-input v-model="queryParams.dun" placeholder="请输入吨位"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="单据号" prop="nos">
                <el-input v-model="queryParams.nos" placeholder="请输入单据号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="是否自制(1:自制; 2:请购; 3:外协)" prop="isdo">
                <el-input v-model="queryParams.isdo" placeholder="请输入是否自制(1:自制; 2:请购; 3:外协)"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="采购单id" prop="mainId">
                <el-input v-model="queryParams.mainId" placeholder="请输入采购单id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="请购单id" prop="qinggouId">
                <el-input v-model="queryParams.qinggouId" placeholder="请输入请购单id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="采购单号" prop="caigouno">
                <el-input v-model="queryParams.caigouno" placeholder="请输入采购单号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="单位" prop="unit">
                <el-input v-model="queryParams.unit" placeholder="请输入单位"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="到货id" prop="daohuoId">
                <el-input v-model="queryParams.daohuoId" placeholder="请输入到货id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="质检日期" prop="zhijianDate">
                            <el-date-picker clearable v-model="queryParams.zhijianDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择质检日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="质检人" prop="zhijianName">
                <el-input v-model="queryParams.zhijianName" placeholder="请输入质检人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="是否质检" prop="isZhijian">
                <el-input v-model="queryParams.isZhijian" placeholder="请输入是否质检"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="质检单" prop="zhijiandan">
                <el-input v-model="queryParams.zhijiandan" placeholder="请输入质检单"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="到货单号" prop="daohuono">
                <el-input v-model="queryParams.daohuono" placeholder="请输入到货单号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="到货日期" prop="daohuodate">
                            <el-date-picker clearable v-model="queryParams.daohuodate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择到货日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="出入库日期" prop="rukudate">
                            <el-date-picker clearable v-model="queryParams.rukudate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择出入库日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="出入库人" prop="rukuren">
                <el-input v-model="queryParams.rukuren" placeholder="请输入出入库人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="出入库批次号" prop="rukuno">
                <el-input v-model="queryParams.rukuno" placeholder="请输入出入库批次号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="出入库数量" prop="daohuoCount">
                <el-input v-model="queryParams.daohuoCount" placeholder="请输入出入库数量"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="是否自制" prop="isDo">
                <el-input v-model="queryParams.isDo" placeholder="请输入是否自制"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:LvRukumingxi:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:LvRukumingxi:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:LvRukumingxi:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:LvRukumingxi:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
                    <el-table-column label="${comment}" align="center" prop="id"/>
            <el-table-column label="产品id" align="center" prop="goodsId"/>
            <el-table-column label="总价" align="center" prop="goodsTotalPrice"/>
            <el-table-column label="成本单价" align="center" prop="goodsBuyPrice"/>
            <el-table-column label="成本总金额" align="center" prop="goodsBuyTotal"/>
            <el-table-column label="销售利润" align="center" prop="goodsProfit"/>
                    <el-table-column label="销售日期" align="center" prop="saleDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.saleDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="供应商" align="center" prop="supplierId"/>
            <el-table-column label="供应商名称" align="center" prop="supplierName"/>
            <el-table-column label="客户" align="center" prop="customerId"/>
            <el-table-column label="客户名称" align="center" prop="customerName"/>
            <el-table-column label="销售人" align="center" prop="saleId"/>
            <el-table-column label="销售人姓名" align="center" prop="saleName"/>
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="订单编号" align="center" prop="projectId"/>
            <el-table-column label="${comment}" align="center" prop="status"/>
            <el-table-column label="是否发货" align="center" prop="isfahuo"/>
                    <el-table-column label="发货时间" align="center" prop="fahuoDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.fahuoDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="产品编码" align="center" prop="code"/>
            <el-table-column label="吨位" align="center" prop="dun"/>
            <el-table-column label="单据号" align="center" prop="nos"/>
            <el-table-column label="是否自制(1:自制; 2:请购; 3:外协)" align="center" prop="isdo"/>
            <el-table-column label="采购单id" align="center" prop="mainId"/>
            <el-table-column label="请购单id" align="center" prop="qinggouId"/>
            <el-table-column label="采购单号" align="center" prop="caigouno"/>
            <el-table-column label="单位" align="center" prop="unit"/>
            <el-table-column label="到货id" align="center" prop="daohuoId"/>
                    <el-table-column label="质检日期" align="center" prop="zhijianDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.zhijianDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="质检人" align="center" prop="zhijianName"/>
            <el-table-column label="是否质检" align="center" prop="isZhijian"/>
            <el-table-column label="质检单" align="center" prop="zhijiandan"/>
            <el-table-column label="到货单号" align="center" prop="daohuono"/>
                    <el-table-column label="到货日期" align="center" prop="daohuodate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.daohuodate, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="出入库日期" align="center" prop="rukudate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.rukudate, '{y}-{m}-{d}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="出入库人" align="center" prop="rukuren"/>
            <el-table-column label="出入库批次号" align="center" prop="rukuno"/>
            <el-table-column label="出入库数量" align="center" prop="daohuoCount"/>
            <el-table-column label="出入库类型" align="center" prop="type"/>
            <el-table-column label="是否自制" align="center" prop="isDo"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:LvRukumingxi:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:LvRukumingxi:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <lvRukumingxi-form ref="form" @ok="getList"></lvRukumingxi-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import LvRukumingxiForm from '@/views/develop/lvRukumingxi/module/LvRukumingxiForm'

    export default {
        name: "LvRukumingxiList",
        components: {
            LvRukumingxiForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 出入库记录表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    goodsId: null,
                    goodsTotalPrice: null,
                    goodsBuyPrice: null,
                    goodsBuyTotal: null,
                    goodsProfit: null,
                    saleDate: null,
                    supplierId: null,
                    supplierName: null,
                    customerId: null,
                    customerName: null,
                    saleId: null,
                    saleName: null,
                    projectId: null,
                    projectName: null,
                    status: null,
                    isfahuo: null,
                    fahuoDate: null,
                    code: null,
                    dun: null,
                    nos: null,
                    isdo: null,
                    mainId: null,
                    qinggouId: null,
                    caigouno: null,
                    unit: null,
                    daohuoId: null,
                    zhijianDate: null,
                    zhijianName: null,
                    isZhijian: null,
                    zhijiandan: null,
                    daohuono: null,
                    daohuodate: null,
                    rukudate: null,
                    rukuren: null,
                    rukuno: null,
                    daohuoCount: null,
                    type: null,
                    isDo: null
                },
                url: {
                    list:'/lvRukumingxi/lvRukumingxi/list',
                    remove:'/lvRukumingxi/lvRukumingxi/',
                    export:'/lvRukumingxi/lvRukumingxi/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询出入库记录列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `lvRukumingxi_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
